package com.hugang.juc.reference;


/**
 * java强引用示例
 * -XX:+PrintGCDetails -Xmx5m -Xms5m
 *
 *
 * @author hg
 * @date 2020/8/26 15:18
 */
public class StrongReferenceDemo {

    public static void main(String[] args) {

        Object o1 = new Object();
        Object o2 = o1;

        System.out.println(o1);
        System.out.println(o2);

        o1 = null;
        try {
            byte[] bytes = new byte[10*1024*1024];
        } catch (Throwable e){
            e.printStackTrace();
        } finally {
            System.out.println(o1);
            //即使OOM，此对象也不会被回收
            System.out.println(o2);
        }
    }
}
